package io.renren.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.renren.common.utils.Constant;
import io.renren.param.ApplicationSaveParam;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * 会议室申请记录
 *
 * @author 1
 * @email 1@2.com
 * @date 2021-08-19 11:56:03
 */
@Data
@TableName("application")
public class ApplicationEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 会议室id
     */
    private Long roomId;
    /**
     * 申请会议室的员工id
     */
    private String employeeId;
    /**
     * 申请会议室的员工名字
     */
    private String employeeName;
    /**
     * 会议主题
     */
    private String subject;
    /**
     * 会议内容
     */
    private String content;
    /**
     * 开始时间
     */
    private Date startTime;
    /**
     * 结束时间
     */
    private Date endTime;
    /**
     * 会议室状态：applied-已申请，signed-已签到，started-已开始，over-已结束,canceled-已取消
     */
    private String state;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    private Date updateTime;
    /**
     * 预约人所在的公司
     */
    private String compId;

    /* 是否人工刷新过了 1=人工刷新过了 */
    private Integer hasManuallyRefreshed;

    /* 人工刷新时间 */
    private Date manuallyRefreshedTime;

    public boolean isManuallyRefreshed() {
        return hasManuallyRefreshed != null && 1 == hasManuallyRefreshed;
    }

    public boolean isMeetingStarted() {
        return StringUtils.equalsIgnoreCase(getState(), Constant.ApplicationState.STARTED.getValue());
    }

    public boolean isMeetingNotBegin() {
        return StringUtils.equalsIgnoreCase(getState(), Constant.ApplicationState.APPLIED.getValue());
    }

    public boolean isMeetingOver() {
        return StringUtils.equalsIgnoreCase(getState(), Constant.ApplicationState.OVER.getValue());
    }

    public boolean isMeetingCanceled() {
        return StringUtils.equalsIgnoreCase(getState(), "canceled");
    }

    public static ApplicationEntity convertFor(ApplicationSaveParam param) {
        ApplicationEntity applicationEntity = new ApplicationEntity();
        if (param == null) {
            return applicationEntity;
        }
        BeanUtils.copyProperties(param, applicationEntity);
//        applicationEntity.setEndTime(DateUtil.offsetMinute(param.getStartTime(), param.getDuration()));
        applicationEntity.setCreateTime(new Date());
        applicationEntity.setUpdateTime(new Date());
        applicationEntity.setState(Constant.ApplicationState.APPLIED.getValue());
        return applicationEntity;
    }

}
